﻿<template id="single_table_operation_template">
    <el-table-column v-if="count" label="操作" :fixed="fixed()" :width="width" align="center">
        <template #header="scope" v-if="$slots.header">
            <el-space><slot name="header" v-bind="scope"></slot></el-space>
        </template>
        <template #default="scope">
            <el-space><slot v-bind="scope"></slot></el-space>
        </template>
    </el-table-column>
</template>
<script type="text/javascript">
    var single_table_operation = {
        template: "#single_table_operation_template",
        data() {
            return {
                width: 0,
                count: 0
            }
        },
        methods: {
            init() {
                var that = this, btnCount = 0, btnTextCount = 0;
                var nodes = that.$slots.default?.({ row: {} });
                that.count = nodes.length;
                nodes.forEach((m, i) => {
                    if (m.type.name == "ElButton") {
                        btnCount++;
                        btnTextCount += m.children.default?.()[0].children.length;
                    }
                });
                that.width = (btnCount * 34) + (btnTextCount * 14) + 28;
            },
            fixed() {
                return app.that.isSmallWidth ? false : 'right';
            }
        },
        mounted() { this.init(); }
    };
</script>